package com.cakebackoffice.clientsoap;


import java.util.HashMap;
import java.util.Map;

public class SoapTest extends Test {
    private Method<? extends Object> method;
    private Map<String, Object> parameters;

    public SoapTest(Method method, Map<String, Object> parameters) {
        this.method = method;
        this.Name = "Test " + method.toString();
        if (parameters != null) {
            this.parameters = parameters;
        }
        if (this.parameters == null) {
            this.parameters = new HashMap<String, Object>();
        }
        this.run();

    }

    @Override
    public void run() {
        try {

            method.setParameters(parameters);
            if (method instanceof ObjectMethod) {
                this.result = ((ObjectMethod) method).getResult();
            } else if (method instanceof StringMethod) {
                this.result = ((StringMethod) method).getResult();
            } else {
                this.result = method.getResult();
            }

            this.isSuccess = true;
        } catch (Exception e) {
            this.isSuccess = false;
            this.result = e.toString();
        }
    }
}
